Completed
Push — master ( 40c2b4...09bd06 )
by Justin
01:29
created

Conclusion.addNote   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
var ExtensibleData = require('./ExtensibleData'),
2
    Attribution = require('./Attribution'),
3
    ResourceReference = require('./ResourceReference'),
4
    Note = require('./Note'),
5
    SourceReference = require('./SourceReference'),
6
    utils = require('./utils');
7
8
/**
9
 * An abstract concept for a basic genealogical data item.
10
 * 
11
 * @constructor
12
 * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
13
 */
14
var Conclusion = function(json){
15
  
16
  // Protect against forgetting the new keyword when calling the constructor
17
  if(!(this instanceof Conclusion)){
18
    return new Conclusion(json);
19
  }
20
  
21
  // If the given object is already an instance then just return it. DON'T copy it.
22
  if(Conclusion.isInstance(json)){
23
    return json;
24
  }
25
  
26
  ExtensibleData.call(this, json);
27
  
28
  if(json){
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if json is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
29
    this.setAttribution(json.attribution);
30
    this.setAnalysis(json.analysis);
31
    this.setConfidence(json.confidence);
32
    this.setLang(json.lang);
33
    this.setNotes(json.notes);
34
    this.setSources(json.sources);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
35
  }
36
};
37
38
Conclusion.prototype = Object.create(ExtensibleData.prototype);
39
40
Conclusion._gedxClass = Conclusion.prototype._gedxClass = 'GedcomX.Conclusion';
41
42
/**
43
 * Check whether the given object is an instance of this class.
44
 * 
45
 * @param {Object} obj
46
 * @returns {Boolean}
47
 */
48
Conclusion.isInstance = function(obj){
49
  return utils.isInstance(obj, this._gedxClass);
50
};
51
52
/**
53
 * Get the attribution.
54
 * 
55
 * @returns {Attribution}
56
 */
57
Conclusion.prototype.getAttribution = function(){
58
  return this.attribution;
59
};
60
61
/**
62
 * Set the attribution
63
 * 
64
 * @param {Object|Attribution} attribution
65
 * @returns {Conclusion} This instance
66
 */
67
Conclusion.prototype.setAttribution = function(attribution){
68
  if(attribution){
69
    this.attribution = new Attribution(attribution);
70
  }
71
  return this;
72
};
73
74
/**
75
 * Get analysis.
76
 * 
77
 * @returns {ResourceReference} analysis
78
 */
79
Conclusion.prototype.getAnalysis = function(){
80
  return this.analysis;
81
};
82
83
/**
84
 * Set the analysis
85
 * 
86
 * @param {Object|ResourceReference} analysis
87
 * @returns {Conclusion} This instance
88
 */
89
Conclusion.prototype.setAnalysis = function(analysis){
90
  if(analysis){
91
    this.analysis = new ResourceReference(analysis);
92
  }
93
  return this;
94
};
95
96
/**
97
 * Get the confidence.
98
 * 
99
 * @returns {String} confidence
100
 */
101
Conclusion.prototype.getConfidence = function(){
102
  return this.confidence;
103
};
104
105
/**
106
 * Set the confidence.
107
 * 
108
 * @param {String} confidence
109
 * @returns {Conclusion} This instance
110
 */
111
Conclusion.prototype.setConfidence = function(confidence){
112
  this.confidence = confidence;
113
  return this;
114
};
115
116
/**
117
 * Get the language identifier.
118
 * 
119
 * @returns {String} lang
120
 */
121
Conclusion.prototype.getLang = function(){
122
  return this.lang;
123
};
124
125
/**
126
 * Set the language identifier.
127
 * 
128
 * @param {String} lang
129
 * @returns {Conclusion} This instance.
130
 */
131
Conclusion.prototype.setLang = function(lang){
132
  this.lang = lang;
133
  return this;
134
};
135
136
/**
137
 * Get the notes
138
 * 
139
 * @returns {Note[]} notes
140
 */
141
Conclusion.prototype.getNotes = function(){
142
  return this.notes || [];
143
};
144
145
/**
146
 * Set the notes
147
 * 
148
 * @param {Object[]|Note[]} notes
149
 * @returns {Conclusion} This instance
150
 */
151
Conclusion.prototype.setNotes = function(notes){
152
  return this._setArray(notes, 'notes', 'addNote');
153
};
154
155
/**
156
 * Add a note
157
 * 
158
 * @param {Object|Note} note
159
 * @returns {Conclusion} This instance
160
 */
161
Conclusion.prototype.addNote = function(note){
162
  return this._arrayPush(note, 'notes', Note);
163
};
164
165
/**
166
 * Get the sources
167
 * 
168
 * @returns {SourceReference[]}
169
 */
170
Conclusion.prototype.getSources = function(){
171
  return this.sources || [];
172
};
173
174
/**
175
 * Set the sources
176
 * 
177
 * @param {Object[]|SourceReference[]} sources
178
 * @returns {Conclusion} This instance
179
 */
180
Conclusion.prototype.setSources = function(sources){
181
  return this._setArray(sources, 'sources', 'addSource');
182
};
183
184
/**
185
 * Add a source
186
 * 
187
 * @param {SourceReference} source
188
 * @returns {Conclusion} This instance
189
 */
190
Conclusion.prototype.addSource = function(source){
191
  return this._arrayPush(source, 'sources', SourceReference);
192
};
193
194
/**
195
 * Export the object as JSON
196
 * 
197
 * @return {Object} JSON object
198
 */
199
Conclusion.prototype.toJSON = function(){
200
  return this._toJSON(ExtensibleData, [
201
    'lang',
202
    'confidence',
203
    'analysis',
204
    'attribution',
205
    'sources',
206
    'notes'
207
  ]);
208
};
209
210
module.exports = Conclusion;